
<script>
var lastClick;
var idDisablePedido;

$(function(){
	$(".sort").tablesorter({widgets: ['zebra']});

	$.getJSON('pedido/getcookielist', {}, function(json)
	{
		var len = json.length;

		for(i = 0; i < len; i++)
		{
			if(json[i])
			{
				$("." + json[i]).show();
				$(".bt" + json[i]).css("background-color", "orange");
			}
		}
	});
});

function openPedido(mesa)
{
	$(".list_todos").hide();
	$(".list_all_menu").hide();

	$.post('pedido/pedido', {cod_mesa: mesa}, function(req)
	{
		$("#editPedido").html(req).fadeIn("fast");
	});
}

function disactivePedido()
{
	var forma_pagamento = $("input:radio[name=fp_radio]:checked").val();
	
	$(".menu_cnew").click();
	
	msg({vmsg: "Fechado.", time: 5000});
	
	$.post('pedido/disactive', {cod_usuario: user.caf01_cod, cod_pedido: idDisablePedido, forma_pagamento: forma_pagamento}, function(req)
	{
		$(".bg_transp").hide();
		$(".resumDiv").fadeOut("fast");
		
		
		printReceive2(idDisablePedido);


		//$("#editPedido").html(req).fadeIn("fast");
	});
}

function printReceive2()
{
	window.open("imprimir/imprimir/cod/" + idDisablePedido, "_blank");
}

function closePedido(id)
{
	$(".bg_transp").show();

	idDisablePedido = id;
	lastClick = id;

	$.post('pedido/list', {cod: id}, function(res)
	{
		$("#resumList").html(res);
		$(".resumDiv").fadeIn("fast");
	});
}

function enableOpt(cls, elm)
{
	var disp = ($("." + cls).css("display"));

	if(disp == "block")
	{
		$("." + cls).fadeOut('fast');
		$(elm).css("background-color", "#e5e5e5");

		$.post('pedido/setcookielist', {tipo: cls, stat: 'delete'});
	}
	else
	{
		$("." + cls).fadeIn('fast');
		$(elm).css("background-color", "orange");

		$.post('pedido/setcookielist', {tipo: cls});
	}
}

function entregue(cod)
{
	$.post('pedido/setentregue', {cod: cod}, function(){
			msg({vmsg: "Ordem entregue. <a href='#'>Desfazer</a>", time: 8000});
			
			$('.bt_list_todos').click();
		}
	)
}

function mostrarFormaPagamento()
{
	$.post('pedido/formas-pagamento', {numeroMesa: lastClick}, function(html){
		$("#ajax-formas-pagamento").html(html);
	});
}

</script>

<div class="ui-corner-all list_all_menu" style="border: 1px solid gray; margin-top: 10px; width: 598px; margin: 0 auto; margin-bottom: 1px;">
	<div onclick="$('.bt_list_todos').click();" style="float: right; position: relative; margin-right: 3px; margin-top: 1px;">
		<img title="Atualizar lista." src="public/images/actions/reload.png" />
	</div>
	<table>
		<tr>
			<td>
			<i>Mostrar:</i>
			</td>
			<td>
				<div class="ui-corner-all button bttakeaway" onclick="enableOpt('takeaway', this);" style="padding: 5px; width: 80px; position: relative; z-index: 1; font-size: 14px; text-align: center; ">
					<div style="">
						Take-away
					</div>
				</div>
			</td>
			<td>
				<div class="ui-corner-all button btmesas" onclick="enableOpt('mesas', this);" style="padding: 5px; width: 80px; position: relative; z-index: 1; font-size: 14px; text-align: center; ">
					<div style="">
						Mesas
					</div>
				</div>
			</td>
			<td>
				<div class="ui-corner-all button btcozinha" onclick="enableOpt('cozinha', this);" style="padding: 5px; width: 80px; position: relative; z-index: 1; font-size: 14px; text-align: center; ">
					<div style="">
						Cozinha
					</div>
				</div>
			</td>
			<td>
				<div class="ui-corner-all button btbar" onclick="enableOpt('bar', this);" style="padding: 5px; width: 80px; position: relative; z-index: 1; font-size: 14px; text-align: center; ">
					<div style="">
						Bar
					</div>
				</div>
			</td>
		</tr>
	</table>
</div>

<div class="list_todos" id="list_todos" style="width: 600px; position: relative; margin: 0 auto; overflow: hidden; height: 350px;">
	<div class="ui-corner-all" style="position: fixed; opacity: 0.8; margin-left: 610px; margin-top: 10px; width: 32px; background: #DFDFDF;">
		<div onclick="moveUp('list_todos');" class="ui-corner-top" style="padding-top: 5px; padding-bottom: 3px; background: #CFCFCF;">
			<img src="public/images/actions/up.png" />
		</div>
		<div onclick="moveDown('list_todos');" class="ui-corner-bottom" style="background: #CFCFCF; margin-top: 1px; padding-top: 7px;">
			<img src="public/images/actions/down.png" />
		</div>
	</div>
	<div style="height: 10px; position: fixed; width: 600px; margin-top: 340px; background-repeat: repeat-x; background-image: url(public/images/bg_bottom.png);">
	</div>
	<div style="height: 15px; position: fixed; width: 600px; background-repeat: repeat-x; background-image: url(public/images/bg_top.png);">
	</div>
	<div style="margin-top: 10px;"></div>
	<div class="takeaway" style="display: none; margin-bottom: 10px;">
		<div style="<?php if(!$this->takeaway) echo "display: none;";?> background-image: url('public/images/bg_menu.png'); background-position: 0 10px; background-repeat: repeat-x; font-size: 20px; color: white; background-color: #7F4500; text-align: center; padding: 5px;" class="ui-widget ui-corner-top">
			Take-away
		</div>
		<div style="<?php if(!$this->takeaway) echo "display: none;";?> border: 1px solid gray; border-top: 0;" class="ui-corner-bottom">
			<table class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead>
					<tr>
						<th nowrap="nowrap">
							Ped
						</th>
						<th>
							Funcionario
						</th>
						<th>
							Hora
						</th>
						<th style="background-image: none;">
						
						</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					foreach ($this->total_ped as $key => $val)
					{
						if($val["mesa"])
						{
							continue;
						}
					?>
					<tr>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["cod"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["user"]; ?>
						</td>
						<td nowrap="nowrap">
							<?php echo Data::getHora($val["data"]); ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<a href="javascript:;" style="padding: 10px; text-decoration: none;" onclick="openPedido(<?php echo $val["cod"]; ?>);">Ver</a>
							|
							<a href="javascript:;" style="padding: 10px; text-decoration: none;" onclick="closePedido(<?php echo $val["cod"]; ?>); lastClick = false;">Fechar</a>
						</td>
					</tr>
					<?php 
					}
					?>
				</tbody>
			</table>
		</div>
	</div>
	
	<!-- normal -->
	<div style="margin-bottom: 10px; display: none;" class="mesas">
		<div style="<?php if(!$this->normal) echo "display: none;";?> background-image: url('public/images/bg_menu.png'); background-position: 0 10px; background-repeat: repeat-x; font-size: 20px; color: white; background-color: #7F4500; text-align: center; padding: 5px;" class="ui-widget ui-corner-top">
			Mesas
		</div>
		<div style="<?php if(!$this->normal) echo "display: none;";?> border: 1px solid gray; border-top: 0;" class="ui-corner-bottom">
			<table class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead style="background-color: #DFDFDF;">
					<tr>
						<th nowrap="nowrap">
							Ped
						</th>
						<th>
							Funcionario
						</th>
						<th>
							Mesa
						</th>
						<th>
							Hora
						</th>
						<th style="background-image: none;">
						
						</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					foreach ($this->total_ped as $key => $val)
					{
						if(!$val["mesa"])
						{
							continue;
						}
					?>
					<tr>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["cod"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["user"]?>
						</td>
						<td>
							<?php echo $val["mesa"]?>
						</td>
						<td>
							<?php echo Data::getHora($val["data"]); ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<a href="javascript:;" style="padding: 10px; text-decoration: none;" onclick="openPedido(<?php echo $val["cod"]; ?>);">Ver</a>
							|
							<a href="javascript:;" style="padding: 10px; text-decoration: none;" onclick="closePedido(<?php echo $val["cod"]; ?>); lastClick = '<?php echo $val["mesa"]; ?>';">Fechar</a>
						</td>
					</tr>
					<?php 
					}
					?>
				</tbody>
			</table>
		</div>
	</div>
	
	<!-- cozinha -->
	<div style="margin-bottom: 10px; display: none;" class="cozinha">
		<div style="<?php if(!$this->cozinha) echo "display: none;";?> background-image: url('public/images/bg_menu.png'); background-position: 0 10px; background-repeat: repeat-x; font-size: 20px; color: white; background-color: #7F4500; text-align: center; padding: 5px;" class="ui-widget ui-corner-top">
			Ordem Cozinha
		</div>
		<div style="<?php if(!$this->cozinha) echo "display: none;";?> border: 1px solid gray; border-top: 0;" class="ui-corner-bottom">
			<table class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead style="background-color: #DFDFDF;">
					<tr>
						<th nowrap="nowrap">
							Ped
						</th>
						<th nowrap="nowrap">
							Produto
						</th>
						<th nowrap="nowrap">
							Mesa
						</th>
						<th nowrap="nowrap">
							Entr
						</th>
						<th nowrap="nowrap">
							Saiu
						</th>
						<th>
							Comentario
						</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					foreach ($this->cozinha as $key => $val)
					{
					?>
					<tr style="<?php if($val["entregue"]){echo "color: green"; }; ?>" onclick="entregue('<?php echo $val["cod_prod"]; ?>');">
						<td width="1%" nowrap="nowrap">
							<?php echo $val["cod"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["prod"]; ?>(<?php echo $val["car"]; ?>)
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["mesa"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["data"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["entregue"]; ?>
						</td>
						<td>
							<?php echo $val["coment"]?>
						</td>
					</tr>
					<?php 
					}
					?>
				</tbody>
			</table>
		</div>
	</div>
	<!-- bar -->
	<div style="margin-bottom: 10px; display: none;" class="bar">
		<div style="<?php if(!$this->bar) echo "display: none;";?> background-image: url('public/images/bg_menu.png'); background-position: 0 10px; background-repeat: repeat-x; font-size: 20px; color: white; background-color: #7F4500; text-align: center; padding: 5px;" class="ui-widget ui-corner-top">
			Ordem Bar
		</div>
		<div style="<?php if(!$this->bar) echo "display: none;";?> border: 1px solid gray; border-top: 0;" class="ui-corner-bottom">
			<table class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead style="background-color: #DFDFDF;">
					<tr>
						<th nowrap="nowrap">
							Ped
						</th>
						<th nowrap="nowrap">
							Produto
						</th>
						<th nowrap="nowrap">
							Mesa
						</th>
						<th nowrap="nowrap">
							Entr
						</th>
						<th nowrap="nowrap">
							Saiu
						</th>
						<th>
							Comentario
						</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					foreach ($this->bar as $key => $val)
					{
					?>
					<tr style="<?php if($val["entregue"]){echo "color: green"; }; ?>" onclick="entregue('<?php echo $val["cod_prod"]; ?>');">
						<td width="1%" nowrap="nowrap">
							<?php echo $val["cod"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["prod"]; ?>(<?php echo $val["car"]; ?>)
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["mesa"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["data"]; ?>
						</td>
						<td width="1%" nowrap="nowrap">
							<?php echo $val["entregue"]; ?>
						</td>
						<td>
							<?php echo $val["coment"]?>
						</td>
					</tr>
					<?php 
					}
					?>
				</tbody>
			</table>
		</div>
	</div>

	<?php 
	if(!$this->normal && !$this->takeaway)
	{
		echo("<div class='msgMesas' style='text-align: center; margin-top: 150px;'><i>Nenhuma ordem pendente.</i></div>");
	}
	?>
</div>
<div style="display: none;" id="editPedido"></div>
<div class="resumDiv ui-corner-all" style="border: 1px solid gray; z-index: 3; background-repeat: repeat-x; padding: 10px; display: none; margin-left: -150px; left: 50%; position: fixed; top: 50px; width: 300px; background-color: white;">
	<div id="desac_btn" onclick="mostrarFormaPagamento();" class="button ui-corner-all" style="padding: 10px; text-align: center; font-size: 16px; margin-bottom: 5px;" >Fechar Mesa</div>
	<div class="button ui-corner-all" onclick="printReceive2();" style="padding: 10px; width: 125px; float: left; position: relative; text-align: center;">Imiprimir</div>
	<div class="button ui-corner-all" onclick="$('.bg_transp').hide(); $('.resumDiv').fadeOut('fast');" style="padding: 10px; width: 125px; margin-bottom: 5px; text-align: center; margin-left: 153px;" >Voltar</div>
	<hr />
	<div id="resumList">
	</div>
</div>
<div id="ajax-formas-pagamento">
</div>